<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<title>javascript语法</title>
	</head>
	<body>
		<h1>javascript语法</h1>
		<h3>1 变量</h3>
		<script type="text/javascript">
			//1变量的使用
			//1.1先声明再赋值 variable
			var num;
			num=10;
			document.write(num+"<br/>");
			//1.2声明同时赋值
			var name="张三";
			document.write(name+"<br/>");
			var address;
			document.write(address+"<br/>");
		</script>
		
		<h3>2数据类型</h3>
		<ul>
			<li>基本(原始)类型</li>
			<li>引用(对象)类型</li>
		</ul>
		
		<script type="text/javascript">
			document.write("<h4>基本类型</h4>");
			/*基本类型5个*/
			var age=20;//number
			var str="我爱javascript";//string
			var gender=true; //boolean
			var email; // undefined 未定义类型
			var obj=null;// null （object）类型 
			
			document.write("age:"+age+" 类型:"+typeof(age));
			document.write("<br/>");
			document.write("str:"+str+" 类型:"+typeof(str));
			document.write("<br/>");
			document.write("gender:"+gender+" 类型:"+typeof(gender));
			document.write("<br/>");
			document.write("email:"+email+" 类型:"+typeof(email));
			document.write("<br/>");
			document.write("obj:"+obj+" 类型:"+typeof(obj));
			document.write("<h4>引用类型</h4>");
			/*引用（对象）类型 */
			//创建"对象定义" 类似 "类"
			function Person(){
				//属性 
				this.name;
				this.age;
				this.gender;
				
				//函数
				this.show=function(){
					document.write("姓名:"+this.name+" 年龄："+this.age+ "性别:"+this.gender);
				}
			}
			//创建对象
			document.write("<br/>");
			var shaobo=new Person();
			shaobo.name="少泊";
			shaobo.age=20;
			shaobo.gender="男";
			shaobo.show();
			
			//使用Object创建对象
			var fahai=new Object();
			fahai.name="发海";
			fahai.age=22;
			fahai.gender="男";
			fahai.address="北京";
			
			fahai.show=function(){
				document.write(this.name+"..."+this.age+" "+this.gender+" "+this.address);
			};
			document.write("<br/>");
			fahai.show();
			document.write("<br/>");
			//javaScript对象的json表示法
			var zhenzhen={"name":"真真","age":20,"gender":"男","address":"上海"};
			document.write(zhenzhen.name);			
			document.write(zhenzhen.age);		
			document.write(zhenzhen.gender);		
			document.write(zhenzhen.address);
			document.write("<h4>数组</h4>");
			//javascript创建数组
			var nums=new Array(3);
			document.write("nums长度:"+nums.length);
			nums[0]=10;
			nums[1]=8;
			nums[2]=20;
			nums[3]=100;
			nums[4]=30;
			nums[5]="xxx";
			document.write("<br/>");
			document.write("nums长度:"+nums.length);
			document.write("<h5>for遍历</h5>");
			
			for(var i=0;i<nums.length;i++){
				document.write(nums[i]+"<br/>");
			}
			document.write("<h5>增强for</h5>");
			
			for(var i in nums){ //i是角标
				document.write(nums[i]+"<br/>");
			}
			
			//创建数组的json表示法
			var names=["zhangsan","lisi","wangwu",100,200];
			document.write(names.length);
			document.write("<br/>");
			for(var i in names){
				document.write(names[i]+"<br/>")
			}
			///------------Array的map使用-----------
			document.write("<h5>map使用</h5>");
			var map=new Array();
			map["cn"]="中国";
			map["usa"]="美国";
			map["uk"]="英国";
			document.write("<br/>");
			document.write("map:"+map.length);
			document.write("<br/>");
			for(var i in map){
				document.write(i+"==="+map[i]+"<br/>");	
			}
			document.write(map.cn);
			document.write(map.usa);
			document.write(map.uk);
			document.write(map['cn']);
			document.write(map['usa']);
			document.write(map['uk']);
		</script>
		<p></p>
	</body>
</html>
